<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="商品名称" field="goods_name">
            <a-input v-model="searchForm.goods_name" placeholder="请输入商品名称" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="用户账号" field="account">
            <a-input v-model="searchForm.account" placeholder="请输入用户账号" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item field="create_time" label="下单时间">
            <a-range-picker v-model="searchForm.create_time" showTime style="width: 100%" />
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
      <template #goods_name="{ record }">
        <span class="text-wrap line-clamp-2 text-xs">{{ record.goods_name }}</span>
      </template>
    </sa-table>
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import api from '../../api/order/comment'

// 引用定义
const crudRef = ref()
const editRef = ref()
const optionData = reactive({})

// 搜索表单
const searchForm = ref({
  goods_name: '',
  account: '',
  create_time: '',
})

// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  rowSelection: { showCheckedAll: true },
  operationColumnWidth: 100,
  delete: {
    show: true,
    auth: ['/app/saiuser/order/comment/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
  },
})

// SaTable 列配置
const columns = reactive([
  { title: '订单编号', dataIndex: 'order_no', width: 180 },
  { title: '商品图片', dataIndex: 'cover_image', type: 'image', size: 48, width: 100 },
  { title: '订单商品', dataIndex: 'goods_name', width: 250 },
  { title: '评论用户', dataIndex: 'account', width: 120 },
  { title: '服务评分', dataIndex: 'score_first', width: 100 },
  { title: '速度评分', dataIndex: 'score_second', width: 100 },
  { title: '产品评分', dataIndex: 'score_third', width: 100 },
  { title: '环境评分', dataIndex: 'score_four', width: 100 },
  { title: '建议', dataIndex: 'content', width: 180 },
  { title: '状态', dataIndex: 'status', type: 'dict', dict: 'data_status', width: 100 },
  { title: '评论时间', dataIndex: 'create_time', width: 180 },
])

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
